package com.plwf.lake.service.impl;

import com.plwf.lake.entity.DriverSchool;
import com.plwf.lake.mapper.DriverSchoolMapper;
import com.plwf.lake.service.DriverSchoolService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Service
public class DriverSchoolServiceImpl implements DriverSchoolService{
    @Resource
    private DriverSchoolMapper mapper;

    @Override
    public List<DriverSchool> query(Map<String, Object> map) {
        return null;
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean save(DriverSchool driverSchool) {
        if(driverSchool.getId()!=null){
            return this.mapper.update(driverSchool);
        }else{
            return this.mapper.insert(driverSchool);
        }
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean remove(Integer id) {
        return this.mapper.delete(id);
    }

    @Override
    public DriverSchool find(Integer id) {
        return this.mapper.selectOne(id);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean enable(Integer id, Integer status) {
        DriverSchool bean = new DriverSchool();
        bean.setId(id);
        bean.setStatus(status);
        return this.mapper.enable(bean);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean updateImage(DriverSchool driverSchool) {
        return this.mapper.updateImage(driverSchool);
    }

    @Override
    public List<DriverSchool> queryAll() {
        return this.mapper.selectAll();
    }
}
